package cn.jlonely.xyhx.app.service.impl;


import cn.jlonely.xyhx.app.mapper.AppReviewMapper;
import cn.jlonely.xyhx.app.mapper.AppVitoMapper;
import cn.jlonely.xyhx.app.service.AppVitoService;
import cn.jlonely.xyhx.pojo.Review;
import cn.jlonely.xyhx.pojo.vo.VitoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AppVitoServiceImpl implements AppVitoService {

    @Autowired
    private AppVitoMapper appVitoMapper;

    @Autowired
    private AppReviewMapper appReviewMapper;

    /**
     * 投票信息
     */
    @Override
    public List<Review> getVitoInfo(Integer id) {
        return appVitoMapper.getVitoInfo(id);
    }

    /**
     * 参与投票
     * @param vitoVo
     */

    @Override
    public void createVito(VitoVo vitoVo) throws Exception {
        boolean flag =  appVitoMapper.selectVito(vitoVo.getUserId(),vitoVo.getRankingId());
        if (flag){
            throw new RuntimeException("您已经参与过该活动了");
        }
        appVitoMapper.createVito(vitoVo);
        /**
         * 给投票数加1
         */
        appReviewMapper.creatNumber(vitoVo.getJudgeId());
    }
}
